home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 47 / scache.s < prev    next >
Encoding:
Text File  |  1987-03-30  |  4.7 KB  |  205 lines

  1.  
  2. *  Small Disk Cache program.
  3. *
  4. *    By Moshe Braner,    870101.
  5. *
  6. *  Caches FAT and root directory only.
  7. *
  8. *  Pure AL version - for a-Seka.  870103.
  9.  
  10. * install the cache into the rwabs() vector
  11.     pea     poke_it
  12.     move.w  #$26,-(a7)        ;   Supexec()
  13.     trap    #14
  14.     addq.l  #6,a7
  15.  
  16. * Cconws("\r\n\n\tDisk Cache installed\r\n\n")
  17.     pea     msg
  18.     move.w  #9,-(a7)
  19.     trap    #1
  20.     addq.l  #6,a7
  21.     
  22. * delay
  23.     clr.l   d0
  24. delay:
  25.     addq.l  #1,d0
  26.     cmp.l   #200000,d0
  27.     blt     delay
  28.  
  29. * terminate, but keep $3300 bytes
  30.     clr.w   -(a7)
  31.     move.l  #$00003300,-(a7)
  32.     move.w  #$31,-(a7)
  33.     trap    #1
  34.  
  35. *  Subroutine to copy a sector (512 bytes)
  36. *    from one RAM area (pointed to by A0) to another (A1).
  37. *
  38. *    D0 is junked.
  39. *    A0,A1 are returned incremented by 512.
  40.  
  41. copy:
  42.     move.l  a0,d0
  43.     btst    #0,d0
  44.     bne.s   ocopy
  45.     move.l  a1,d0
  46.     btst    #0,d0
  47.     bne.s   ocopy
  48.     move.w  #31,d0
  49. eloop:
  50.     move.l  (a0)+,(a1)+
  51.     move.l  (a0)+,(a1)+
  52.     move.l  (a0)+,(a1)+
  53.     move.l  (a0)+,(a1)+
  54.     dbf     d0,eloop
  55.     rts
  56. ocopy:
  57.     move.w  #511,d0
  58. oloop:
  59.     move.b  (a0)+,(a1)+
  60.     dbf     d0,oloop
  61.     rts
  62.  
  63. *  Our resident-utility-protocol stuff:
  64.  
  65.     dc.b  "CACH"        ; magic number
  66. old:
  67.     dc.l  0            ; space for old vector
  68.  
  69. *  Cache code:
  70.  
  71. *    chache logical sectors 6-17 for drives A and B
  72. *    check for media change before using cached data
  73. *    read from cached data when possible
  74. *    refresh chache after writing or real reading
  75.  
  76. scache:
  77.     move.w  14(a7),d7        ; drive    
  78.     cmp.w   #2,d7        ; drive A or B ?
  79.     blt.s   doit        ;  then cache    
  80. usual:
  81.     move.l  old,a0        ; old vector    
  82.     jmp     (a0)
  83. doit:
  84.     move.l  $47e,a3        ; mediach() vector
  85.     move.w  d7,-(a7)        ; drive no.    
  86.     jsr     (a3)
  87.     addq.l  #2,a7
  88.     lea     mark,a3        ; cache validity table
  89.     move.w  12(a7),d6        ; sector no.    
  90.     beq.s   junk        ; junk if reading BPB
  91.     tst.l   d0            ; mediach() result
  92.     beq.s   noch        ; no media change
  93. junk:
  94.     move.l  a3,a0
  95.     tst.w   d7            ; drive    
  96.     beq.s   ja
  97.     adda.w  #12,a0
  98. ja:
  99.     clr.l   (a0)+        ; junk all sectors
  100.     clr.l   (a0)+
  101.     clr.l   (a0)+
  102. noch:
  103.     subi.w  #6,d6        ; we start at sector 6
  104.     bmi.s   usual
  105.     move.w  10(a7),d5        ; count of sectors
  106.     add.w   d6,d5        ; last sector    
  107.     cmpi.w  #11,d5
  108.     bgt.s   usual
  109.     tst.w   d7            ; drive    
  110.     beq.s   ra
  111.     add.w   #12,d5        ; offset for drive B
  112.     add.w   #12,d6
  113. ra:
  114.     tst.w   4(a7)        ; rwflag
  115.     bne.s   write
  116.     lea     space,a0        ; source    
  117.     move.w  d6,d0
  118.     asl.w   #8,d0        ; add 512*sec    
  119.     asl.w   #1,d0
  120.     adda.w  d0,a0        ; real source    
  121.     move.l  6(a7),a1        ; destination    
  122. rloop:
  123.     tst.b   0(a3,d6)        ; sector cache valid?
  124.     beq.s   write
  125.     bsr     copy
  126.     addq.w  #1,d6
  127.     cmp.w   d5,d6        ; any more sectors?
  128.     blt.s   rloop
  129.     clr.l   d0            ; no errors    
  130.     rts
  131. write:
  132.     move.w  d5,d7
  133.     sub.w   d6,d7        ; what's left    
  134.     move.w  10(a7),d0        ; old sec count
  135.     move.w  d7,10(a7)        ; new count    
  136.     sub.w   d7,d0        ; the part done
  137.     add.w   d0,12(a7)        ; new first sector
  138.     move.w  d6,d0
  139. jloop:
  140.     clr.b   0(a3,d0)        ; sector cache invalid
  141.     addq.w  #1,d0
  142.     cmp.w   d5,d0        ; any more sectors?
  143.     bne.s   jloop
  144.     lea     retsav,a0
  145.     move.l  (a7)+,(a0)        ; save return address
  146.     pea     comeback        ; our return address
  147.     bra     usual        ; do usual but return
  148. comeback:
  149.     move.l  retsav,-(a7)    ; restore return addr
  150.     tst.l   d0            ; any errors?    
  151.     bne.s   exit        ; then return it
  152.     move.w  12(a7),d6        ; sec no.
  153.     subi.w  #6,d6
  154.     move.w  10(a7),d5        ; count of sectors
  155.     add.w   d6,d5        ; last sector    
  156.     move.w  14(a7),d7        ; drive    
  157.     beq.s   mb
  158.     add.w   #12,d5        ; offset for drive B
  159.     add.w   #12,d6
  160. mb:
  161.     lea     mark,a3        ; cache validity table
  162.     move.l  6(a7),a0        ; source    
  163.     lea     space,a1        ; destination    
  164.     move.w  d6,d0
  165.     asl.w   #8,d0        ; add 512*sec    
  166.     asl.w   #1,d0
  167.     adda.w  d0,a1        ; real destination
  168. wloop:
  169.     lea     0(a3,d6),a4
  170.     bset    #0,(a4)        ; mark sector cache
  171.     bsr     copy
  172.     addq.w  #1,d6
  173.     cmp.w   d5,d6        ; any more sectors?
  174.     blt.s   wloop
  175.     clr.l   d0            ; no errors    
  176. exit:
  177.     rts
  178. retsav:
  179.     dc.l    0
  180. mark:
  181.     dc.l    0,0,0        ; 12 bytes for drive A
  182.     dc.l    0,0,0        ; 12 bytes for drive B
  183.  
  184. space:                ; cache buffer here
  185.  
  186. poke_it:
  187.     move.l  #$476,a1        ; rwabs() vector
  188.     move.l  (a1),a0        ; old vector    
  189.     move.l  -8(a0),d0        ; magic there?    
  190.     cmpi.l  #$43414348,d0        
  191.     beq.s   dont        ; then skip    
  192.     lea     scache,a0
  193.     move.l  (a1),-4(a0)        ; save old vector
  194.     move.l  a0,(a1)        ; put new vector
  195. dont:
  196.     rts
  197.  
  198. msg:
  199.     dc.b    13,10,10,9
  200.     dc.b    "Disk Cache installed"
  201.     dc.b    13,10,10,0
  202.     even
  203.  
  204.     end
  205.